package org.teachertools.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import org.teachertools.data.Eleve;

public class EleveValidator implements Validator {

    @SuppressWarnings("unchecked")
    @Override
    public boolean supports(Class clazz) {
        return Eleve.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "prenom", "error.form.required", new String[] { "prenom" });
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nom", "error.form.required", new String[] { "nom" });
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "classe", "error.form.required", new String[] { "classe" });
    }
}
